package com.brillilab.starter.utils;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import com.brillilab.common.constant.ResultEnum;
import com.brillilab.common.entity.ResponseVo;

import lombok.extern.slf4j.Slf4j;

/**
 * Respons响应输出Util
 * @author lj
 *
 */
@Slf4j
public class RespOutWithUtil {

	/** 
     * 以JSON格式输出 
     * @param response 
     */  
	public static void outWithJson(HttpServletResponse response,ResultEnum resultEnum,String message) {  
        response.setCharacterEncoding("UTF-8");  
        response.setContentType("application/json; charset=utf-8");  
        PrintWriter out = null;  
        try {  
            out = response.getWriter();  
            //将实体对象转换为JSON Object转换  
            out.append(JSONObject.toJSONString(ResponseVo.failure(resultEnum,message,null)));
        } catch (IOException e) {  
            log.error(">>>>>> JSON输出异常 ",e);
        } finally {  
            if (out != null) {  
                out.close();  
            }  
        }  
    } 
    
}
